<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="user" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{userHome.managed ? 'Edit' : 'Add'} User</f:facet>




            <s:decorate id="enabledField" template="layout/edit.xhtml">
                <ui:define name="label">Enabled</ui:define>
                <h:selectBooleanCheckbox id="enabled"
                                      value="#{userHome.instance.enabled}"/>
            </s:decorate>


            <s:decorate id="firstNameField" template="layout/edit.xhtml">
                <ui:define name="label">First name</ui:define>
                <h:inputText id="firstName"
                           size="40"
                      maxlength="40"
                          value="#{userHome.instance.firstName}">
                    <a:support event="onblur" reRender="firstNameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="lastNameField" template="layout/edit.xhtml">
                <ui:define name="label">Last name</ui:define>
                <h:inputText id="lastName"
                           size="25"
                      maxlength="25"
                          value="#{userHome.instance.lastName}">
                    <a:support event="onblur" reRender="lastNameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="passwordField" template="layout/edit.xhtml">
                <ui:define name="label">Password</ui:define>
                <h:inputText id="password"
                           size="50"
                      maxlength="50"
                          value="#{userHome.instance.password}">
                    <a:support event="onblur" reRender="passwordField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>



            <s:decorate id="saltField" template="layout/edit.xhtml">
                <ui:define name="label">Salt</ui:define>
                <h:inputText id="salt"
                           size="50"
                      maxlength="50"
                          value="#{userHome.instance.salt}">
                    <a:support event="onblur" reRender="saltField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="userNameField" template="layout/edit.xhtml">
                <ui:define name="label">User name</ui:define>
                <h:inputText id="userName"
                       required="true"
                           size="20"
                      maxlength="20"
                          value="#{userHome.instance.userName}">
                    <a:support event="onblur" reRender="userNameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{userHome.persist}"
                       disabled="#{!userHome.wired}"
                       rendered="#{!userHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{userHome.update}"
                       rendered="#{userHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{userHome.remove}"
                      immediate="true"
                       rendered="#{userHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/User.xhtml"
                rendered="#{userHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty userFrom ? 'UserList' : userFrom}.xhtml"
                rendered="#{!userHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Autorizacoes">
        <h:form styleClass="association" id="autorizacoesChildren">

            <h:outputText value="There are no autorizacoes associated with this user."
                       rendered="#{empty userHome.autorizacoes}"/>

            <rich:dataTable value="#{userHome.autorizacoes}"
                           var="_userAuthorization"
                      rendered="#{not empty userHome.autorizacoes}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="autorizacoesTable">
                <rich:column sortBy="#{_userAuthorization.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_userAuthorization.id}"/>
                </rich:column>
                <rich:column sortBy="#{_userAuthorization.amount}">
                    <f:facet name="header">Amount</f:facet>
                    <h:outputText value="#{_userAuthorization.amount}">
                        <f:convertNumber/>
                    </h:outputText>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{userHome.managed}" id="autorizacoes">
        <div class="actionButtons">
            <s:button id="adduserAuthorization"
                   value="Add userAuthorization"
                    view="/UserAuthorizationEdit.xhtml"
             propagation="none">
                 <f:param name="userId"
                         value="#{userHome.instance.id}"/>
                 <f:param name="userAuthorizationFrom" value="User"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
